package com.program.cloudmanagesystem.hotel.controller;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.program.cloudmanagesystem.hotel.domain.*;
import com.program.cloudmanagesystem.hotel.service.HotelService;
//import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

//import javax.jws.WebParam;
//import javax.jws.soap.SOAPBinding;
import java.util.List;

@RestController
@RefreshScope
@RequestMapping("/")
public class HotelController {
    @NacosInjected
    @Autowired
    private HotelService hotelService;

    @GetMapping("/Hotel")
    public List<Hotel> showHotels(){
        return hotelService.showHotels();
    }

    @GetMapping("/test")
    public String test(){
        return "hello world";
    }

    @PostMapping ("/searchHotel")
    public Hotel searchHotel(@RequestBody Hotel hotel){
        return hotelService.searchHotel(hotel.getId());
    }

    @GetMapping("/searchHotelByName")
    public List<Hotel> searchHotelByName(String keyword){
        return hotelService.searchHotelsByname(keyword);
    }

    @PostMapping("/insertHotel")
    public String insertHotel(@RequestBody Hotel hotel){
        hotelService.insertHotel(hotel);
        return "OK";
    }

    @PostMapping ("/deleteHotel")
    public String deleteHotel(@RequestBody Hotel hotel){
        hotelService.deleteHotel(hotel.getId());
        return "OK";
    }

    @PostMapping("/updateData")
    public String updateData(@RequestBody Hotel hotel){
        hotelService.updateData(hotel);
        return "OK";
    }

    @PostMapping("/updateNow")
    public String updateNow(@RequestBody Hotel hotel) {
        hotelService.updateData(hotel);
        return "OK";
    }
   @PostMapping("/updateScore")
    public String updateScore(@RequestBody Hotel hotel) {
        hotelService.updateScore(hotel);
        return "OK";
   }

}
